package com.ld.util;

import java.util.Random;

public class CodeUtil {
    //生成验证码
    public static String getCode(){
        char[] chs=new char[52];
        for (int i = 0; i < chs.length; i++) {
            if (i<26){
                chs[i]=(char)(65+i);
            } else {
                chs[i]=(char)(65+i+6);
            }
//            System.out.print(chs[i]+" ");
        }
        String str ="";
        Random r=new Random();
        for (int i = 0; i < 4; i++) {
            str +=chs[r.nextInt(52)];
        }
        str +=r.nextInt(10);

        Random r1 =new Random();
        char[] c= str.toCharArray();
        for (int i = 0; i < c.length; i++) {
            int randomIndex= r1.nextInt(c.length);
            char temp=c[i];
            c[i]=c[randomIndex];
            c[randomIndex]=temp;
        }
        String result=new String(c);
//        System.out.println(str);
//        System.out.println(result);
        return result;
    }
}
